package com.fl.nettydemo.c3;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.DefaultPromise;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.concurrent.Promise;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

/**
 * 测试异步结果集promise
 */
@Slf4j
public class TestPromiseTask {
    @SneakyThrows
    public static void main(String[] args) {
        NioEventLoopGroup group = new NioEventLoopGroup();
        DefaultPromise<Integer> promise = new DefaultPromise<>(group.next());
        EventLoop loop = group.next();
        loop.submit(() -> {
            try {
                log.info("开始业务处理");
                promise.setSuccess(88);
            } catch (Exception e) {
                promise.setFailure(e);
            }
        }).sync();
        log.info("{}",promise.getNow());



    }
}
